package prometheus

import (
	"testing"
)

func Test_calculateUsage(t *testing.T) {
	values := [][]interface{}{
		{1660010280, "1.0184682158287774"},
		{1660010340, "0.6635018388785169"},
		{1660010400, "0.8380707672310364"},
		{1660010460, "0.6197425273333332"},
		{1660010520, "1.1365606777548167"},
		{1660010580, "1.0666610460651313"},
		{1660010640, "1.1459490526929743"},
		{1660010700, "0.5215568474615817"},
		{1660010760, "1.4232269026666662"},
		{1660010820, "1.1622978139666658"},
		{1660010880, "0.9792096495866116"},
		{1660010940, "1.173405202633334"},
		{1660011000, "0.9366493575333341"},
		{1660011060, "0.9466778167394405"},
		{1660011120, "0.7519664609666658"},
		{1660011180, "0.9556144043666639"},
		{1660011240, "1.0133540760999986"},
		{1660011300, "1.313870467066666"},
		{1660011360, "0.6126731979333347"},
		{1660011420, "1.1970386828243789"},
		{1660011480, "1.0451394028666678"},
		{1660011540, "0.870224026136817"},
		{1660011600, "1.14468409441259"},
		{1660011660, "0.7360759719333297"},
		{1660011720, "1.1099658403666732"},
		{1660011780, "1.045828198466673"},
		{1660011840, "0.8633174657666662"},
		{1660011900, "1.2297277712923775"},
		{1660011960, "1.2099699102000008"},
		{1660012020, "1.199594678590481"},
		{1660012080, "1.2563158949666635"},
		{1660012140, "1.2342684971670457"},
		{1660012200, "1.1902225470062695"},
	}
	type args struct {
		values [][]interface{}
	}
	tests := []struct {
		name    string
		args    args
		want    float64
		wantErr bool
	}{
		{
			name:    "测试prometheus数据计算",
			args:    args{values},
			want:    1.0185402819637026,
			wantErr: false,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := calculateUsage(tt.args.values)
			if (err != nil) != tt.wantErr {
				t.Errorf("calculateUsage() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if got != tt.want {
				t.Errorf("calculateUsage() got = %v, want %v", got, tt.want)
			}
		})
	}
}
